﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

using Global.Class.Library;

namespace DataTransferObject
{
    public class GCGBPasteCollection : NotifyPropertyChangeObject
    {

        private int gcgbCommandID;
        private int gcgbCommandSerialID;
        private DateTime gcgbCommandDate;

        private int workerNameID;

        private int materialSemiID;
        private double remainsQuantity;
        private double quantity;
        private double quantityLoss;
        private double quantityBad;                       

        private string remarks;


        public GCGBPasteCollection()
            : this(0, 0, DateTime.Today, 0, 0, 0, 0, 0, 0, "")
        {
        }

        public GCGBPasteCollection(int gcgbCommandID, int gcgbCommandSerialID, DateTime gcgbCommandDate, int workerNameID, int materialSemiID, double remainsQuantity, double quantity, double quantityLoss, double quantityBad, string remarks)
        {
            //GlobalDefaultValue.Apply(this);
            this.StopTracking();

            this.GCGBCommandID = gcgbCommandID;
            this.GCGBCommandSerialID = gcgbCommandSerialID;
            this.GCGBCommandDate = gcgbCommandDate;

            this.WorkerNameID = workerNameID;

            this.MaterialSemiID = materialSemiID;         

            this.RemainsQuantity = remainsQuantity;
            this.Quantity = quantity;
            this.QuantityLoss = quantityLoss;
            this.QuantityLoss = quantityBad;

            this.Remarks = remarks;

            this.StartTracking();
        }


        #region Properties



        [DefaultValue(0)]
        public int GCGBCommandID
        {
            get { return this.gcgbCommandID; }
            set { ApplyPropertyChange<GCGBPasteCollection, int>(ref this.gcgbCommandID, o => o.GCGBCommandID, value); }
        }

        [DefaultValue(0)]
        public int GCGBCommandSerialID
        {
            get { return this.gcgbCommandSerialID; }
            set { ApplyPropertyChange<GCGBPasteCollection, int>(ref this.gcgbCommandSerialID, o => o.GCGBCommandSerialID, value); }
        }

        [DefaultValue(typeof(DateTime), "01/01/1900")]
        public DateTime GCGBCommandDate
        {
            get { return this.gcgbCommandDate; }
            set { ApplyPropertyChange<GCGBPasteCollection, DateTime>(ref this.gcgbCommandDate, o => o.GCGBCommandDate, value); }
        }


        [DefaultValue(0)]
        public int WorkerNameID
        {
            get { return this.workerNameID; }
            set { ApplyPropertyChange<GCGBPasteCollection, int>(ref this.workerNameID, o => o.WorkerNameID, value); }
        }

        [DefaultValue(0)]
        public int MaterialSemiID
        {
            get { return this.materialSemiID; }
            set { ApplyPropertyChange<GCGBPasteCollection, int>(ref this.materialSemiID, o => o.MaterialSemiID, value); }
        }
       

       [DefaultValue(0)]
        public double RemainsQuantity
        {
            get { return this.remainsQuantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBPasteCollection, double>(ref this.remainsQuantity, o => o.RemainsQuantity, value);
            }
        }


        [DefaultValue(0)]
        public double Quantity
        {
            get { return this.quantity; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBPasteCollection, double>(ref this.quantity, o => o.Quantity, value);
            }
        }

        [DefaultValue(0)]
        public double QuantityLoss
        {
            get { return this.quantityLoss; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBPasteCollection, double>(ref this.quantityLoss, o => o.QuantityLoss, value);
            }
        }

        [DefaultValue(0)]
        public double QuantityBad
        {
            get { return this.quantityBad; }
            set
            {
                value = Math.Round(value, GlobalVariables.Round0Quantity);
                ApplyPropertyChange<GCGBPasteCollection, double>(ref this.quantityBad, o => o.QuantityBad, value);
            }
        }



        [DefaultValue("")]
        public string Remarks
        {
            get { return this.remarks; }
            set { ApplyPropertyChange<GCGBPasteCollection, string>(ref this.remarks, o => o.Remarks, value); }
        }

        public GCGBPasteCollection ShallowClone()
        {
            return (GCGBPasteCollection)this.MemberwiseClone();
        }


        #endregion

        protected override System.Collections.Generic.List<ValidationRule> CreateRules()
        {
            List<ValidationRule> validationRules = base.CreateRules();
            validationRules.Add(new SimpleValidationRule("Quantity", "Over remainning quantity.", delegate { return this.Quantity + this.QuantityLoss + this.QuantityBad <= this.RemainsQuantity; }));          

            return validationRules;
        }
    }
}


